﻿using System;
using System.Security.Principal;
using DomainModel;
using Repository.Abstract;
using Services.Abstract;

namespace Services.Concrete
{
    public class SubjectService : Service<Subject>, ISubjectService
    {
        private readonly ISubjectRepository _subjectRepository;

        public SubjectService(ISubjectRepository subjectRepository, IPrincipal currentUser, IPermissionService permissionService)
            : base(subjectRepository, currentUser, permissionService)
        {
            _subjectRepository = subjectRepository;
        }

        public new void Delete(Subject subject)
        {
            if (!PermissionService.CanCUDSubjects())
                throw new Exception("Недостаточно прав для CUD операций с предметами.");

            base.Delete(subject);
        }

        public new void SaveOrUpdate(Subject subject)
        {
            if (!PermissionService.CanCUDSubjects())
                throw new Exception("Недостаточно прав для CUD операций с предметами.");

            if (string.IsNullOrEmpty(subject.Name))
                throw new Exception("Не введено название.");

            base.SaveOrUpdate(subject);
        }
    }
}